void OpenADC ( unsigned char ,
unsigned char ,
unsigned char );
unsigned int ReadADC( void );
void SetChanADC ( unsigned char );


#define ADC_RIGHT_JUST 0b11111111
#define ADC_LEFT_JUST 0b01111111


#define ADC_0_TAD 0b11000111
#define ADC_2_TAD 0b11001111
#define ADC_4_TAD 0b11010111
#define ADC_6_TAD 0b11011111
#define ADC_8_TAD 0b11100111
#define ADC_12_TAD 0b11101111
#define ADC_16_TAD 0b11110111
#define ADC_20_TAD 0b11111111


#define ADC_FOSC_2 0b11111000
#define ADC_FOSC_8 0b11111001
#define ADC_FOSC_32 0b11111010
//#define ADC_FRC_4 0b11111011
#define ADC_FOSC_4 0b11111100
#define ADC_FOSC_16 0b11111101
#define ADC_FOSC_64 0b11111110
#define ADC_FOSC_RC 0b11111111


#define ADC_VREFPLUS_VDD ADC_REF_VDD_VDD
#define ADC_VREFPLUS_EXT ADC_REF_VDD_VREFPLUS
#define ADC_VREFMINUS_VSS ADC_REF_VDD_VSS
#define ADC_VREFMINUS_EXT ADC_REF_VDD_VREFMINUS


#define ADC_REF_VDD_VDD 0b11110011
#define ADC_REF_VDD_VREFPLUS 0b11110111
#define ADC_REF_VDD_FVREF 0b11111011


#define ADC_REF_VDD_VSS 0b11111100
#define ADC_REF_VDD_VREFMINUS 0b11111101


#define ADC_CH3 0b11001111
#define ADC_CH4 0b11010011
#define ADC_CH5 0b11010111
#define ADC_CH6 0b11011011
#define ADC_CH7 0b11011111
#define ADC_CH8 0b11100011
#define ADC_CH9 0b11100111
#define ADC_CH10 0b11101011
#define ADC_CH11 0b11101111
#define DAC1 0b11111011
#define FVR1 0b11111111


#define ADC_Enable 0b11111111
#define ADC_Disable 0b11111110


#define ADC_INT_ON 0b11111111
#define ADC_INT_OFF 0b01111111

#define ADC_INT_ENABLE() (PIR1bits.ADIF=0,INTCONbits.PEIE=1,PIE1bits.ADIE=1)
#define ADC_INT_DISABLE() (PIE1bits.ADIE=0)


#define CloseADC() (ADCON0bits.ADON=0,PIE1bits.ADIE=0)
#define ConvertADC() (ADCON0bits.GO=1)
#define BusyADC() (ADCON0bits.NOT_DONE)


void OpenADC ( unsigned char rADCON2,
unsigned char rADCON1,
unsigned char rADCON0){
rADCON0 &= 0b11111101; // GO = 0, ADON =1
if ((rADCON0 & 0b10000000) == 0){
ADC_INT_DISABLE();
}else{
ADC_INT_ENABLE();
}
ADCON2 = rADCON2;
ADCON1 = rADCON1;
ADCON0 = rADCON0;
}


unsigned int ReadADC( void ){
return ((ADRESH*256) + ADRESL);
}


void SetChanADC ( unsigned char ChCode){
ADCON0 = (ADCON0 | 0b00111100) & ChCode;
}





            戻る